from pydub import AudioSegment
from pydub.silence import split_on_silence
from os import getpid,mkdir

# split return names
def splitwav( name:str, ext=0 )->list:
	pid = getpid()
	tmp = f'/tmp/{pid}{ext}'
	sound = AudioSegment.from_wav(name)
	segments = split_on_silence(sound, min_silence_len=300, silence_thresh=-50,keep_silence=130)
	try:
		mkdir( tmp )
	except:
		None
	names = []
	for i in range(len(segments)):
		fn = f'{tmp}/a{i:04}.wav'
		#print( type(segments[i]) )
		segments[i].export( fn )
		names.append( fn )
	return names
